'''
@文件    :views.py
@说明    :
@时间    :2020/04/05 14:59:58
@作者    :didiplus
@版本    :1.0
'''

from .__init__ import *
from flask import Blueprint,make_response,jsonify,json,request
mv = Blueprint('mv',__name__,url_prefix='/api/mv')

@mv.route('/all',methods=['POST','GET'])
def all():
    # 全部MV
    query = request_query(request,
                          ["area", {"area": "全部"}],cd
                          ["type", {"type": "全部"}],
                          ["order", {"order": "上升最快"}],
                          ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    query["total"] = "true"
    dic = {"tags": json.dumps({"地区": query["area"], "类型": query["type"], "排序": query["order"]}),
           "offset": query["offset"],
           "limit": query["limit"],
           "total": "true"}
    data = Send(dic).POST("https://interface.music.163.com/weapi/mv/all")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/new',methods=['POST','GET'])
def new():
    # 最新MV
    query = request_query(request,
                          ["area", {"area": ""}],
                          ["limit", {"limit": 30}])
    query["total"] = True
    data = Send(query).POST("https://interface.music.163.com/weapi/mv/first")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/netease',methods=['POST','GET'])
def netease():
    # 网易出品MV
    query = request_query(request,
                          ["limit", {"limit": 10}],
                          ["offset", {"offset": 0}])
    data = Send(query).POST("https://interface.music.163.com/weapi/mv/exclusive/rcmd")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/recommend',methods=['POST','GET'])
def recommend():
    # 推荐MV
    data = Send().POST("weapi/personalized/mv")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/simi',methods=['POST','GET'])
def simi():
    # 相似MV
    query = request_query(request, "mvid")
    data = Send(query).POST("weapi/discovery/simiMV")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/top',methods=['POST','GET'])
def top():
    # MV排行
    query = request_query(request,
                          ["area", {"area": ""}],
                          ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    data = Send(query).POST("weapi/mv/toplist")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/detail',methods=['POST','GET'])
def detail():
    # MV详情
    query = request_query(request, ["mvid", "id"])
    data = Send(query).POST("weapi/mv/detail")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/url',methods=['POST','GET'])
def url():
    # MV地址
    query = request_query(request, ["mvid", "id"], ["r", {"r": 1080}])
    data = Send(query).POST("weapi/song/enhance/play/mv/url")
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/sub',methods=['POST','GET'])
def sub():
    # 收藏/取消收藏 MV
    query = request_query(request, ["mvid", "mvId"], ["t", {"t": 1}])
    t = "sub" if query.pop("t") == "1" else "unsub"
    query["mvIds"] = '["' + query["mvId"] + '"]'
    data = Send(query).POST("weapi/mv/" + t)
    return make_response(jsonify(json.loads(data.text)),403)

@mv.route('/sublist',methods=['POST','GET'])
def sublist():
    # 收藏的 MV 列表
    query = request_query(request,
                          ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    query["total"] = True
    data = Send(query).POST("weapi/cloudvideo/allvideo/sublist")
    return make_response(jsonify(json.loads(data.text)),403)
